﻿<local:ForecastPage x:Class="EmperialApps.WeatherSpark.ChooseLocationPage"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                    xmlns:local="clr-namespace:EmperialApps.WeatherSpark"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
                    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
                    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
                    FontFamily="{StaticResource PhoneFontFamilyNormal}"
                    FontSize="{StaticResource PhoneFontSizeNormal}"
                    Foreground="{StaticResource PhoneForegroundBrush}"
                    Orientation="Portrait"
                    SupportedOrientations="Portrait"
                    mc:Ignorable="d"
                    d:DesignHeight="768"
                    d:DesignWidth="480"
                    shell:SystemTray.IsVisible="True">

    <ScrollViewer>
        <Grid x:Name="LayoutRoot"
              Background="Transparent">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <StackPanel x:Name="TitlePanel"
                        Grid.Row="0"
                        Margin="12,17,0,0">
                <TextBlock Style="{StaticResource PhoneTextNormalStyle}"
                           x:Name="ApplicationTitle"
                           Text="WᴇᴀᴛʜᴇʀSᴘᴀʀᴋ" />
                <TextBlock Style="{StaticResource PhoneTextTitle1Style}"
                           x:Name="PageTitle"
                           Margin="9,-7,0,0"
                           FontSize="64"
                           Text="{Binding Mode=OneTime, Source={StaticResource Localized}, Path=Strings.ChooseLocationPage_header}" />
            </StackPanel>

            <ListBox x:Name="DebugLog"
                     Grid.Row="1"
                     Height="0"
                     ScrollViewer.HorizontalScrollBarVisibility="Auto"
                     Margin="{StaticResource PhoneHorizontalMargin}"
                     FontSize="18" />

            <Grid x:Name="ContentPanel"
                  Grid.Row="1"
                  Margin="{StaticResource PhoneHorizontalMargin}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <local:FixedAutoCompleteBox x:Name="Search"
                                            Grid.Row="0"
                                            FilterMode="None"
                                            GotFocus="OnSearchGotFocus"
                                            InputScope="PostalCode"
                                            KeyUp="OnSearchKeyUp"
                                            LostFocus="OnSearchLostFocus"
                                            MaxDropDownHeight="230"
                                            MinimumPrefixLength="0"
                                            SelectionChanged="OnSearchSelectionChanged"
                                            TextChanged="OnSearchTextChanged"
                                            ValueMemberPath="Name">
                    <toolkit:AutoCompleteBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Style="{StaticResource PhoneTextNormalStyle}"
                                       Margin="{StaticResource PhoneTouchTargetOverhang}"
                                       FontSize="{StaticResource PhoneFontSizeMediumLarge}"
                                       Foreground="#FF000000">
                            <Run Text="{Binding Name}" />
                            <Run Foreground="{StaticResource PhoneTextBoxReadOnlyBrush}"
                                 Text="{Binding County}" />
                            </TextBlock>
                        </DataTemplate>
                    </toolkit:AutoCompleteBox.ItemTemplate>
                </local:FixedAutoCompleteBox>

                <TextBlock Style="{StaticResource PhoneTextLargeStyle}"
                           x:Name="SearchHint"
                           Grid.Row="0"
                           Margin="24,0"
                           FontSize="{StaticResource PhoneFontSizeMediumLarge}"
                           Foreground="{StaticResource PhoneTextBoxReadOnlyBrush}"
                           IsHitTestVisible="False"
                           Text="{Binding Mode=OneTime, Source={StaticResource Localized}, Path=Strings.ChooseLocationPage_hint}"
                           VerticalAlignment="Center" />

                <TextBlock Style="{StaticResource PhoneTextSubtleStyle}"
                           Grid.Row="1"
                           FontStyle="Italic"
                           Text="{Binding Mode=OneTime, Source={StaticResource Localized}, Path=Strings.ChooseLocationPage_separator}"
                           TextAlignment="Center" />

                <ToggleButton x:Name="DiscoverLocation"
                              Grid.Row="2"
                              Click="OnDiscoverLocationClicked"
                              Content="{Binding Mode=OneTime, Source={StaticResource Localized}, Path=Strings.ChooseLocationPage_DiscoverLocation}" />

                <StackPanel x:Name="StatusPanel"
                            Grid.Row="3">
                    <StackPanel.Resources>
                        <DataTemplate x:Key="SearchButtonTemplate">
                            <Button Style="{StaticResource RoundButton}"
                                    Background="{Binding ActionImage}"
                                    Content="{Binding}"
                                    IsEnabled="{Binding IsNew}">
                                <Button.ContentTemplate>
                                    <DataTemplate>
                                        <StackPanel>
                                            <Canvas>
                                                <Grid Canvas.Left="-74"
                                                      Canvas.Top="66"
                                                      Width="66">
                                                    <TextBlock Style="{StaticResource PhoneTextSubtleStyle}"
                                                               Margin="0"
                                                               FontSize="{StaticResource PhoneFontSizeSmall}"
                                                               HorizontalAlignment="Center"
                                                               Text="{Binding Source}" />
                                                </Grid>
                                            </Canvas>

                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto" />
                                                    <ColumnDefinition Width="*" />
                                                </Grid.ColumnDefinitions>

                                                <Ellipse Height="18"
                                                         Margin="0,2,8,0"
                                                         Width="18"
                                                         Fill="{StaticResource PhoneAccentBrush}"
                                                         HorizontalAlignment="Left"
                                                         VerticalAlignment="Center"
                                                         Visibility="{Binding DiscoverMarkVsibility}">
                                                    <Ellipse.OpacityMask>
                                                        <RadialGradientBrush>
                                                            <GradientStop Color="Black"
                                                                          Offset="0" />
                                                            <GradientStop Color="Black"
                                                                          Offset="0.5" />
                                                            <GradientStop Color="Transparent"
                                                                          Offset="0.5" />
                                                            <GradientStop Color="Transparent"
                                                                          Offset="0.75" />
                                                            <GradientStop Color="Black"
                                                                          Offset="0.75" />
                                                            <GradientStop Color="Black"
                                                                          Offset="1" />
                                                        </RadialGradientBrush>
                                                    </Ellipse.OpacityMask>
                                                </Ellipse>

                                                <TextBlock Grid.Column="1"
                                                           Text="{Binding PlaceName, FallbackValue=Searching...}" />
                                            </Grid>

                                            <ProgressBar Padding="0"
                                                         IsIndeterminate="{Binding IsSearching}"
                                                         Value="{Binding SearchProgress}" />

                                            <Grid>
                                                <ItemsControl ItemsSource="{Binding Updates}">
                                                    <ItemsControl.ItemTemplate>
                                                        <DataTemplate>
                                                            <TextBlock Style="{StaticResource PhoneTextSubtleStyle}"
                                                                       Margin="0"
                                                                       Text="{Binding}"
                                                                       TextWrapping="Wrap" />
                                                        </DataTemplate>
                                                    </ItemsControl.ItemTemplate>
                                                </ItemsControl>

                                                <ContentPresenter Content="{Binding FallbackProgress}"
                                                                  HorizontalAlignment="Right"
                                                                  VerticalAlignment="Top" />
                                            </Grid>
                                        </StackPanel>
                                    </DataTemplate>
                                </Button.ContentTemplate>
                            </Button>
                        </DataTemplate>
                    </StackPanel.Resources>

                    <!--<ContentPresenter ContentTemplate="{StaticResource SearchButtonTemplate}" />-->
                </StackPanel>
            </Grid>
        </Grid>
    </ScrollViewer>
</local:ForecastPage>
